<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>数据同步配置</title>
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link href="/static/basic/plugins/fontawesome-free-5.15.4-web/css/all.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/static/m.css" >
	
</head>
<body>
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center',title:'数据同步配置'" >
		<table id="detailGrid" ></table>
	</div>
	<div data-options="region:'west',collapsible:false,split:true,title:'数据同步配置明细'" style="width:40%;">
		<div class="easyui-layout" data-options="fit:true" style="">
			<table id="mainGrid" ></table>
		</div>
	</div>
</div>
<div id="searchbar">
<div class="maction">
		<a href="javascript:void(0)" id="btn1" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-plus mbutton'">新增</a>
		<a href="javascript:void(0)" id="btn3" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-trash-alt mbutton color-c5'">删除</a>
		<a href="javascript:void(0)" id="saveButton1" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
	<a href="javascript:void(0)" id="updateBtn1" class="easyui-linkbutton" data-options="plain:true,iconCls:'mbutton'">执行同步</a>
</div>
<form id="searchForm" >
	比较定义<input id="search-compareConfigId" name="compareConfigId" class="easyui-textbox" >
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-search mbutton'" >查询</a>
</form>
</div>
<div id="searchbar2">
<div class="maction">
		<a href="javascript:void(0)" id="btn4" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-plus mbutton'">新增</a>
		<a href="javascript:void(0)" id="btn6" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-trash-alt mbutton color-c5'">删除</a>
		<a href="javascript:void(0)" id="saveButton2" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
</div>
	<form id="searchForm2" >
		<a id="searchButton2" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-search mbutton'" >查询</a>
	</form>
</div>
<script src="/static/basic/plugins/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
<script src="/static/init.js"></script>
<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
<script src="/static/searchEdit.js?v=12"></script>
<!-- <script src="/static/basic/plugins/moment.min.js"></script> -->
<script>
var mainId;//主表id
var editRow=null;
//document ready
$(function(){
	grid1=new uniontrip.datagrid.searchEdit({
		page_id:"399198655995707392",
		grid_id:"mainGrid",
		sqlname:"grid_399198655995707392_excel_update_config",
		showCheckbox:false,
		rownumbers:false,
		toolbar_id:"searchbar",
		gridParam:{"ascOrDesc":"desc","orderBy":"id"},
		onClickRow:function(rowIndex, rowData){
			if(rowData.id!=mainId){
				mainId=rowData.id;
				grid2.loadParam({updateConfigId:mainId});
			}
		},
		column_formatter:{
			content:function(value,row,index){
				//return value;
				return "<pre style='overflow:hidden'>"+value+"</pre>";
			},
			example:function(value,row,index){
				//return value;
				return "<pre style='overflow:hidden'>"+value+"</pre>";
			},
		},
		searchParamOperator:{
			title:"contain"
		},
	});
	grid2=new uniontrip.datagrid.searchEdit({
		page_id:"399198655995707393",
		//initColumnUrl:"/authenticated/grid/column/v2/379254889454895104",
		grid_id:"detailGrid",
		sqlname:"grid_399198655995707393_excel_update_config_detail",
		showCheckbox:false,
		rownumbers:false,
		paging:"yes",
		autoload:true,
		toolbar_id:"searchbar2",
		gridParam:{"ascOrDesc":"asc","orderBy":"id"},
		column_formatter:{
			value:function(value,row,index){
				//return value;
				return "<pre style='overflow:hidden'>"+value+"</pre>";
			},
		},
		searchParamOperator:{
		},
	});
	//tab
	$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
	$('#searchButton2').bind('click',grid2.load);//查询操作绑定事件
	//row
	//$('#addButton').bind('click', addRow);//新增行绑定事件
	//$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
	//$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
	$('#saveButton1').bind('click', grid1.accept);//保存datagrid绑定事件
	$('#saveButton2').bind('click', grid2.accept);
	//$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
	//$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
	//$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
    $('#updateBtn1').bind('click',function(){
		var selectRows=grid1.grid.datagrid('getSelections');
		if(selectRows.length>0){
			$.post("/compare/updateByUpdateConfigId",{updateConfigId:selectRows[0].id},function(result){
				if(result.success){
					info("操作成功！");
				}else{
					$.messager.alert("提示", "操作失败！<br>"+result.message);
				}
			});
		}else{
			$.messager.alert("提示", "请选择一条数据！");
		}
	});

    //初始化搜索框
    initsearch();
	$('#btn1').bind('click', addRow);//新增行绑定事件
	$('#btn3').bind('click',function(){gridConfirm(grid1.grid,"是否确认删除？",deleteSubmit);});//删除行绑定事件

	$('#btn4').bind('click', addDetailRow);//新增行绑定事件
    $('#btn6').bind('click',function (){
    	gridConfirm(grid2.grid,"是否确认删除？",function (row){
    		$.post("/authenticated/ajax/updates/grid_399198655995707393_excel_update_config_detail-delete",{ids:[row.id]},function(result){
    			if(result.success){
    				info("删除成功！");
    				grid2.loadParam({updateConfigId:mainId});
    			}else{
    				$.messager.alert("提示", "删除失败！<br>"+result.message);
    			}
    		});
    	});
    });//删除行绑定事件


});


/**
 * 新增一行
 */
function addRow(){
//ROW
	var newRowData={id:guid()};//初始化行数据,creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')
	grid1.grid.datagrid('append',newRowData);	
	//tab
}

function addDetailRow(){
//ROW
	var newRowData={id:guid(),updateConfigId:mainId};//初始化行数据,creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')
	grid2.grid.datagrid('append',newRowData);
	//tab
}
/**
 * 删除提交
 * @param selectRow
 */
function deleteSubmit(selectRow){
	$.post("/authenticated/ajax/updates/grid_399198655995707392_excel_update_config-delete",JSON.stringify({ids:[selectRow.id]}),function(result){
		if(result.success){
			$.messager.alert("提示", "删除成功！");
			grid1.load();
			//删除子表
		}
	});
}


/**
 * 初始化搜索条件
 */
function initsearch(){
	/*$('#search-product_class_id').combotree({
		panelHeight:'auto',
		icons: [{
			iconCls:'icon-clear',
			handler:function(){
				$('#search-product_class_id').combotree('clear');
			}
		}],
	    data:grid1.combotreeDatas.product_class_id
	});
	//初始化combobox例子
	*/
	$('#search-compareConfigId').combobox({
		panelHeight:'auto',
		editable:false,
		valueField:'codeValue',
		textField:'codeName',
		icons: [{
			iconCls:'icon-clear',
			handler:function(e){
				$(e.data.target).combobox('clear');
			}
		}],
		data:grid1.comboboxDatas.compareConfigId
	});
}
</script>
</body>
</html>